1f044faedd01317b71c3abf91ac935beb6581223,public/java/src/org/broadinstitute/sting/gatk/walkers/phasing/PhaseByTransmission.java,PhaseByTransmission,phaseTrioGenotypes,#Allele#Allele#Genotype#Genotype#Genotype#ArrayList#,531

Before Change


        double bestConfigurationLikelihood = 0.0;
        double norm = 0.0;
        boolean isMV = false;
        int bestConfigurationGenotypeDiffs=4;
        Genotype.Type bestMotherGenotype = getTypeSafeNull(mother);
        Genotype.Type bestFatherGenotype = getTypeSafeNull(father);
        Genotype.Type bestChildGenotype = getTypeSafeNull(child);

        //Get the most likely combination
        //Only check for most likely combination if at least a parent and the child have genotypes
        if(childLikelihoods.size()>2 && (motherLikelihoods.size() + fatherLikelihoods.size())>3){
            int mvCount;
            double configurationLikelihood;
            int configurationGenotypeDiffs;
            for(Map.Entry<Genotype.Type,Double> motherGenotype : motherLikelihoods.entrySet()){
                for(Map.Entry<Genotype.Type,Double> fatherGenotype : fatherLikelihoods.entrySet()){
                    for(Map.Entry<Genotype.Type,Double> childGenotype : childLikelihoods.entrySet()){
                        mvCount = mvCountMatrix.get(motherGenotype.getKey()).get(fatherGenotype.getKey()).get(childGenotype.getKey());
                        configurationLikelihood =  mvCount>0 ? Math.pow(deNovoPrior,mvCount)*motherGenotype.getValue()*fatherGenotype.getValue()*childGenotype.getValue() : (1.0-11*deNovoPrior)*motherGenotype.getValue()*fatherGenotype.getValue()*childGenotype.getValue();
                        norm += configurationLikelihood;
                        configurationGenotypeDiffs = countFamilyGenotypeDiff(mother.getType(),father.getType(),child.getType(),motherGenotype.getKey(),fatherGenotype.getKey(),childGenotype.getKey());
                        //Keep this combination if
                        //It has a better likelihood
                        //Or it has the same likelihood but requires less changes from original genotypes
                        if ((configurationLikelihood > bestConfigurationLikelihood) ||
                                (configurationLikelihood == bestConfigurationLikelihood && configurationGenotypeDiffs < bestConfigurationGenotypeDiffs)) {
                            bestConfigurationLikelihood = configurationLikelihood;
                            bestMotherGenotype = motherGenotype.getKey();
                            bestFatherGenotype = fatherGenotype.getKey();
                            bestChildGenotype = childGenotype.getKey();
                            isMV = mvCount>0;
                            bestConfigurationGenotypeDiffs=configurationGenotypeDiffs;
                        }
                    }
                }

After Change


        //Prior vars
        double bestConfigurationLikelihood = 0.0;
        double norm = 0.0;
        int configuration_index =0;
        ArrayList<Boolean> isMV = new ArrayList<Boolean>();
        isMV.add(false);
        ArrayList<Genotype.Type> bestMotherGenotype = new ArrayList<Genotype.Type>();
        bestMotherGenotype.add(getTypeSafeNull(mother));
        ArrayList<Genotype.Type> bestFatherGenotype = new ArrayList<Genotype.Type>();
        bestFatherGenotype.add(getTypeSafeNull(father));
        ArrayList<Genotype.Type> bestChildGenotype = new ArrayList<Genotype.Type>();
        bestChildGenotype.add(getTypeSafeNull(child));

        //Get the most likely combination
        //Only check for most likely combination if at least a parent and the child have genotypes
        if(childLikelihoods.size()>2 && (motherLikelihoods.size() + fatherLikelihoods.size())>3){
            int mvCount;
            double configurationLikelihood;
            for(Map.Entry<Genotype.Type,Double> motherGenotype : motherLikelihoods.entrySet()){
                for(Map.Entry<Genotype.Type,Double> fatherGenotype : fatherLikelihoods.entrySet()){
                    for(Map.Entry<Genotype.Type,Double> childGenotype : childLikelihoods.entrySet()){
                        mvCount = mvCountMatrix.get(motherGenotype.getKey()).get(fatherGenotype.getKey()).get(childGenotype.getKey());
                        configurationLikelihood =  mvCount>0 ? Math.pow(deNovoPrior,mvCount)*motherGenotype.getValue()*fatherGenotype.getValue()*childGenotype.getValue() : (1.0-11*deNovoPrior)*motherGenotype.getValue()*fatherGenotype.getValue()*childGenotype.getValue();
                        norm += configurationLikelihood;
                        //Keep this combination if
                        //It has a better likelihood
                        //Or it has the same likelihood but requires less changes from original genotypes
                        if (configurationLikelihood > bestConfigurationLikelihood){
                            bestConfigurationLikelihood = configurationLikelihood;
                            isMV.clear();
                            isMV.add(mvCount>0);
                            bestMotherGenotype.clear();
                            bestMotherGenotype.add(motherGenotype.getKey());
                            bestFatherGenotype.clear();
                            bestFatherGenotype.add(fatherGenotype.getKey());
                            bestChildGenotype.clear();
                            bestChildGenotype.add(childGenotype.getKey());
                        }
                        else if(configurationLikelihood == bestConfigurationLikelihood) {
                            bestMotherGenotype.add(motherGenotype.getKey());
                            bestFatherGenotype.add(fatherGenotype.getKey());
                            bestChildGenotype.add(childGenotype.getKey());
                            isMV.add(mvCount>0);
                        }
                    }
                }
            }

            //normalize the best configuration probability
            bestConfigurationLikelihood = bestConfigurationLikelihood / norm;

            //In case of multiple equally likely combinations, take a random one
            if(bestMotherGenotype.size()>1){
                configuration_index = rand.nextInt(bestMotherGenotype.size()-1);
            }

        }
        else{
            bestConfigurationLikelihood = NO_TRANSMISSION_PROB;
        }

            TrioPhase phasedTrioGenotypes = transmissionMatrix.get(bestMotherGenotype.get(configuration_index)).get(bestFatherGenotype.get(configuration_index)).get(bestChildGenotype.get(configuration_index));

            //Return the phased genotypes
            phasedTrioGenotypes.getPhasedGenotypes(ref,alt,mother,father,child,bestConfigurationLikelihood,finalGenotypes);
            return isMV.get(configuration_index);

    }